﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Syndication;
using System.Xml;

namespace FeedReader.Shared
{
    public class RssFeedReader
    {
        private SyndicationFeed result;
        private Feed thefeed;

        private RssFeedReader(string server, string extension)
        {
            this.Loadfeed(server,extension);
        }

        public Feed Loadfeed(string server, string extension)
        {
            result = GetReaderFeed(server, extension);

            thefeed = new Feed(result);
            return thefeed;
        }

        public static RssFeedReader Create(string server, string extension)
        {
            return new RssFeedReader(server, extension);
        }
        private SyndicationFeed GetReaderFeed(string server, string extension)
        {
            XmlReader result;
            try
            {
                result = XmlReader.Create(server);

                return SyndicationFeed.Load(result);

            }
            catch
            {

            }
            return null;
        }


        public Feed GetFeed()
        {
            return this.thefeed;
        }
    }
}
